package ai.llz.ai_pro;

import com.hankcs.hanlp.seg.common.Term;

public class SegamentResult implements Comparable<SegamentResult>{
    private String word;
    private String nature;
    private int seq;

    @Override
    public int compareTo(SegamentResult o) {
        if (getNature().equals(o.getNature())){
            return o.seq - seq;
        }
        String[] arr = new String[]{"nrf","nx","v","n"};
        for (String s : arr) {
            int r = compare(s,o);
            if (r != 0){
                return r;
            }
        }
        return o.seq - seq;
    }

    private int compare(String name,SegamentResult o2){
        if (name.equals(getNature())){
            return -1;
        }
        else if (name.equals(o2.getNature())){
            return 1;
        }
        return 0;
    }

    public SegamentResult(Term term, int seq) {
        this.word = term.word;
        this.nature = term.nature.toString();
        this.seq = seq;
    }

    public SegamentResult() {
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public String getNature() {
        return nature;
    }

    public void setNature(String nature) {
        this.nature = nature;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    @Override
    public String toString() {
        return word + "," + nature + ',' + seq;
    }
}
